/**
 * @param {number[]} arr1
 * @param {number[]} arr2
 * @return {number[]}
 */
var addNegabinary = function (arr1, arr2) {
  let num1 = 0, num2 = 0
  for (let i = arr1.length - 1; i >= 0; i--) {
    num1 +=arr1[arr1.length - 1 - i]!=0?  ((-2) * arr1[arr1.length - 1 - i]) ** i:0

  }

  for (let i = arr2.length - 1; i >= 0; i--) {
    num2 +=arr2[arr2.length - 1 - i]!=0? ((-2) * arr2[arr2.length - 1 - i]) ** i:0
  }

  let num = num1 + num2
  let arr = []
  while (num != 0 && num != 1 && num != -1) {
    arr.push(Math.abs(num % (-2)))
    num = Math.ceil(num / -2)
  }
  if (num == 1) {
    arr.push(num)
  } else if (num == -1) {
    arr.push(1, 1)
  }else{
    arr.push(0)
  }

  return arr.reverse()
};

addNegabinary([0], [1])
addNegabinary([1,1,1,1,1], [1,0,1])